﻿using System;
using System.Windows.Input;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SkiTracker.ViewModel;

namespace SkiTracker.View
{
    public partial class ConversationPage : PhoneApplicationPage
    {
        public ConversationPage()
        {
            InitializeComponent();

            DataContext = new ConversationViewModel();

            ViewModel.SendCommand.CanExecuteChanged +=
                (sender, args) => ((ApplicationBarIconButton) ApplicationBar.Buttons[0]).IsEnabled = ViewModel.SendCommand.CanExecute(null);
        }


        private ConversationViewModel ViewModel { get { return DataContext as ConversationViewModel; } }

        private void Send_Click(object sender, EventArgs e)
        {
            ViewModel.SendCommand.Execute(null);
        }

        private void SendHelp_Click(object sender, EventArgs e)
        {
            ViewModel.SendFixCommand.Execute("Brauche Hilfe");
        }

        private void Refresh_Click(object sender, EventArgs e)
        {
            ViewModel.RefreshCommand.Execute(null);
        }

        private void MenuItem_Click(object sender, EventArgs e)
        {
            ViewModel.SendFixCommand.Execute(((ApplicationBarMenuItem)sender).Text);            
        }

        private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter) ViewModel.SendCommand.Execute(null);
        }

    }
}